<script setup lang="ts" name="ProfileUser">
import { formatDate } from '@/utils/dateUtil'
import UserAvatar from './UserAvatar.vue'
import { ProfileType } from '@/api/system/user/profile'
import { PropType } from 'vue'

defineProps({
  userInfo: { type: Object as PropType<ProfileType> }
})

const { t } = useI18n()
</script>

<template>
  <div v-if="userInfo">
    <div class="text-center">
      <UserAvatar :img="userInfo.avatar" />
    </div>
    <ul class="list-group list-group-striped">
      <li class="list-group-item">
        <SvgIcon class="mr-5px" icon="ep:user" />
        {{ t('profile.user', 'username') }}
        <div class="pull-right">{{ userInfo?.username }}</div>
      </li>
      <li class="list-group-item">
        <SvgIcon class="mr-5px" icon="ep:phone" />
        {{ t('profile.user', 'mobile') }}
        <div class="pull-right">{{ userInfo?.mobile }}</div>
      </li>
      <li class="list-group-item">
        <SvgIcon class="mr-5px" icon="ep:message" />
        {{ t('profile.user', 'mail') }}
        <div class="pull-right">{{ userInfo?.email }}</div>
      </li>
      <li class="list-group-item">
        <SvgIcon class="mr-5px" icon="ri:team-line" />
        {{ t('profile.user', 'dept') }}
        <div v-if="userInfo?.dept" class="pull-right">{{ userInfo?.dept.name }}</div>
      </li>
      <li class="list-group-item">
        <SvgIcon class="mr-5px" icon="ep:suitcase" />
        {{ t('profile.user', 'posts') }}
        <div v-if="userInfo?.posts" class="pull-right">
          {{ userInfo?.posts.map((post) => post.name).join(',') }}
        </div>
      </li>
      <li class="list-group-item">
        <SvgIcon class="mr-5px" icon="ri:group-line" />
        {{ t('profile.user', 'roles') }}
        <div v-if="userInfo?.roles" class="pull-right">
          {{ userInfo?.roles.map((role) => role.name).join(',') }}
        </div>
      </li>
      <li class="list-group-item">
        <SvgIcon class="mr-5px" icon="ep:calendar" />
        {{ t('profile.user', 'createTime') }}
        <div class="pull-right">{{ formatDate(userInfo?.create_time!) }}</div>
      </li>
    </ul>
  </div>
</template>

<style scoped lang="scss">
.text-center {
  position: relative;
  margin-bottom: var(--el-space);
  overflow: hidden;
  text-align: center;
}

.list-group-striped > .list-group-item {
  padding-right: 0;
  padding-left: 0;
  line-height: 1.2;
  border-right: 0;
  border-left: 0;
  border-radius: 0;

  .el-icon{
    vertical-align: -2px;
  }
}

.list-group {
  padding-left: 0;
  list-style: none;
}

.list-group-item {
  padding: 12px 0;
  margin-bottom: -1px;
  font-size: 14px;
  border-top: 1px solid var(--el-border-color-light);
  border-bottom: 1px solid var(--el-border-color-light);
}

.pull-right {
  float: right !important;
}
</style>
